<template>
  <div class="app-container">
    <SearchFilter size="mini" :maxShow="9" @search="handleQuery" @reset="resetQuery">
<!--    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">-->
      <el-form-item label="客户名" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入客户名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户昵称" prop="nickName">
        <el-input
          v-model="queryParams.nickName"
          placeholder="请输入客户昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户类型" prop="customerType">
        <el-select v-model="queryParams.customerType" placeholder="请选择客户类型" clearable>
          <el-option
            v-for="dict in dict.type.custom_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="线索级别" prop="userType">
        <el-select v-model="queryParams.userType" placeholder="请选择线索级别" clearable>
          <el-option
            v-for="dict in dict.type.customer_level"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="用户邮箱" prop="email">
        <el-input
          v-model="queryParams.email"
          placeholder="请输入用户邮箱"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable>
          <el-option
            v-for="dict in dict.type.sys_user_sex"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="线索渠道" prop="clueChannel">
        <el-select v-model="queryParams.clueChannel" placeholder="请选择线索渠道" clearable>
          <el-option
            v-for="dict in dict.type.clue_channels"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="线索来源" prop="dataSource">
        <el-select v-model="queryParams.dataSource" placeholder="请选择线索来源" clearable>
          <el-option
            v-for="dict in dict.type.customer_source"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="转介绍" prop="refCustomerId">
        <el-input
          v-model="queryParams.refCustomerId"
          placeholder="请输入转介绍关联的客户ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="居住区域" prop="liveAddress">
        <el-input
          v-model="queryParams.liveAddress"
          placeholder="请输入客户居住 区县/区域"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择客户状态" clearable>
          <el-option
            v-for="dict in dict.type.customer_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="daterangeCreateTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="是否大客户" prop="isBigCustomer">
        <el-select v-model="queryParams.isBigCustomer" placeholder="请选择是否大客户" clearable>
          <el-option
            v-for="dict in dict.type.sys_yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="大客户" prop="bigCustomer">
        <el-select v-model="queryParams.bigCustomer" placeholder="请选择大客户" clearable>
          <el-option
            v-for="dict in dict.type.big_customer_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="大客户单位" prop="bigCustomerDtl">
        <el-input
          v-model="queryParams.bigCustomerDtl"
          placeholder="请输入大客户企业单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="微信" prop="wechat">
        <el-input
          v-model="queryParams.wechat"
          placeholder="请输入微信"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="征信情况" prop="creditInvestigation">
        <el-select v-model="queryParams.creditInvestigation" placeholder="请选择征信情况" clearable>
          <el-option
            v-for="dict in dict.type.credit_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="付款方式" prop="payWay">
        <el-select v-model="queryParams.payWay" placeholder="请选择付款方式" clearable>
          <el-option
            v-for="dict in dict.type.car_pay_method"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="按揭类型" prop="payMortgageType">
        <el-select v-model="queryParams.payMortgageType" placeholder="请选择付款按揭类型" clearable>
          <el-option
            v-for="dict in dict.type.mortgage_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否有旧车" prop="isExistModel">
        <el-select v-model="queryParams.isExistModel" placeholder="请选择是否有旧车" clearable>
          <el-option
            v-for="dict in dict.type.sys_yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="旧车型" prop="existModels">
        <el-input
          v-model="queryParams.existModels"
          placeholder="请输入旧车置换/保有车型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="旧车是否评估" prop="isAssessment">
        <el-input
          v-model="queryParams.isAssessment"
          placeholder="请输入旧车是否评估"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="旧车评估价格" prop="assessmentPrice">
        <el-input
          v-model="queryParams.assessmentPrice"
          placeholder="请输入旧车评估价格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="意向车型颜色" prop="intentionCarColor">
        <el-input
          v-model="queryParams.intentionCarColor"
          placeholder="请输入意向车型颜色"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="意向车型" prop="intentionCarModels">
        <el-input
          v-model="queryParams.intentionCarModels"
          placeholder="请输入意向车系,车型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="对比车型" prop="contrastCarModels">
        <el-input
          v-model="queryParams.contrastCarModels"
          placeholder="请输入对比车型"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销售员" prop="saleUser">
        <el-input
          v-model="queryParams.saleUser"
          placeholder="请输入销售员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否试驾" prop="isTestDrive">
        <el-input
          v-model="queryParams.isTestDrive"
          placeholder="请输入是否试驾"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否报价" prop="isOffer">
        <el-input
          v-model="queryParams.isOffer"
          placeholder="请输入是否报价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否金融" prop="isFinance">
        <el-input
          v-model="queryParams.isFinance"
          placeholder="请输入是否金融"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预计到店时间" prop="preToStoreDate">
        <el-date-picker clearable
                        v-model="queryParams.preToStoreDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择预计到店时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="最后一次到店" prop="lastToStoreDate">
        <el-date-picker clearable
                        v-model="queryParams.lastToStoreDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择最后一次到店日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="4S店" prop="storeName">
        <el-input
          v-model="queryParams.storeName"
          placeholder="请输入4S店"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="下单日期" prop="orderDate">
        <el-date-picker clearable
                        v-model="queryParams.orderDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择下单日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="到店状态" prop="storeStatus">
        <el-select v-model="queryParams.storeStatus" placeholder="请选择到店状态" clearable>
          <el-option
            v-for="dict in dict.type.to_store_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
<!--    </el-form>-->
    </SearchFilter>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:customer:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:customer:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:customer:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:customer:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"  :pageName="$options.name" ></right-toolbar>
    </el-row>

    <el-table  border  v-loading="loading"   style="width: 100%" :data="customerList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="客户ID" align="center" prop="id"  v-if="columns[0].visible" show-overflow-tooltip />
      <el-table-column label="客户名" align="center" prop="userName" v-if="columns[1].visible" show-overflow-tooltip />
      <el-table-column label="微信昵称" align="center" prop="nickName" v-if="columns[2].visible" show-overflow-tooltip />
      <el-table-column label="客户类型" align="center" prop="customerType" v-if="columns[3].visible" show-overflow-tooltip >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.custom_type" :value="scope.row.customerType"/>
        </template>
      </el-table-column>
      <el-table-column label="线索级别" align="center" prop="userType" v-if="columns[4].visible" show-overflow-tooltip >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.customer_level" :value="scope.row.userType"/>
        </template>
      </el-table-column>
      <el-table-column label="用户邮箱" align="center" prop="email" v-if="columns[5].visible" show-overflow-tooltip />
      <el-table-column label="电话" align="center" prop="phone" v-if="columns[6].visible" show-overflow-tooltip />
      <el-table-column label="性别" align="center" prop="sex" v-if="columns[7].visible" show-overflow-tooltip >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex"/>
        </template>
      </el-table-column>
      <el-table-column label="头像地址" align="center" prop="avatar" v-if="columns[8].visible" show-overflow-tooltip />
      <el-table-column label="线索渠道" align="center" prop="clueChannel" v-if="columns[9].visible" show-overflow-tooltip >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.clue_channels" :value="scope.row.clueChannel"/>
        </template>
      </el-table-column>
      <el-table-column label="线索来源" align="center" prop="dataSource" v-if="columns[10].visible" show-overflow-tooltip >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.customer_source" :value="scope.row.dataSource"/>
        </template>
      </el-table-column>
      <el-table-column label="转介绍" align="center" prop="refCustomerId" v-if="columns[11].visible" show-overflow-tooltip />
      <el-table-column label="居住区域" align="center" prop="liveAddress" v-if="columns[12].visible" show-overflow-tooltip />
      <el-table-column label="客户状态" align="center" prop="status" v-if="columns[13].visible" show-overflow-tooltip >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.customer_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
<!--      <el-table-column label="最后登录IP" align="center" prop="loginIp" v-if="columns[15].visible" show-overflow-tooltip />-->
<!--      <el-table-column label="最后登录时间" align="center" prop="loginDate" width="180" v-if="columns[16].visible" show-overflow-tooltip  >-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.loginDate, '{y}-{m}-{d}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="创建时间" align="center" prop="createTime" v-if="columns[18].visible" show-overflow-tooltip  >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" v-if="columns[21].visible" show-overflow-tooltip />
      <el-table-column label="是否大客户" align="center" prop="isBigCustomer" v-if="columns[22].visible" show-overflow-tooltip >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.isBigCustomer"/>
        </template>
      </el-table-column>
      <el-table-column label="大客户" align="center" prop="bigCustomer" v-if="columns[23].visible" show-overflow-tooltip >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.big_customer_type" :value="scope.row.bigCustomer"/>
        </template>
      </el-table-column>
      <el-table-column label="大客户单位" align="center" prop="bigCustomerDtl" v-if="columns[24].visible" show-overflow-tooltip />
      <el-table-column label="微信" align="center" prop="wechat" v-if="columns[25].visible" show-overflow-tooltip />
      <el-table-column label="购车类型" align="center" prop="buyCarType" v-if="columns[26].visible" show-overflow-tooltip />
      <el-table-column label="征信情况" align="center" prop="creditInvestigation" v-if="columns[27].visible" show-overflow-tooltip >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.credit_status" :value="scope.row.creditInvestigation"/>
        </template>
      </el-table-column>
      <el-table-column label="付款方式" align="center" prop="payWay" v-if="columns[28].visible" show-overflow-tooltip >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.car_pay_method" :value="scope.row.payWay"/>
        </template>
      </el-table-column>
      <el-table-column label="按揭类型" align="center" prop="payMortgageType" v-if="columns[29].visible" show-overflow-tooltip >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mortgage_type" :value="scope.row.payMortgageType"/>
        </template>
      </el-table-column>
      <el-table-column label="是否有旧车" align="center" prop="isExistModel" v-if="columns[30].visible" show-overflow-tooltip >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.isExistModel"/>
        </template>
      </el-table-column>
      <el-table-column label="旧车型" align="center" prop="existModels" v-if="columns[31].visible" show-overflow-tooltip />
      <el-table-column label="旧车是否评估" align="center" prop="isAssessment" v-if="columns[32].visible" show-overflow-tooltip />
      <el-table-column label="旧车评估价格" align="center" prop="assessmentPrice" v-if="columns[33].visible" show-overflow-tooltip />
      <el-table-column label="意向车型颜色" align="center" prop="intentionCarColor" v-if="columns[34].visible" show-overflow-tooltip />
      <el-table-column label="意向车型" align="center" prop="intentionCarModels" v-if="columns[35].visible" show-overflow-tooltip />
      <el-table-column label="对比车型" align="center" prop="contrastCarModels" v-if="columns[36].visible" show-overflow-tooltip />
      <el-table-column label="销售员" align="center" prop="saleUser" v-if="columns[37].visible" show-overflow-tooltip />
      <el-table-column label="是否试驾" align="center" prop="isTestDrive" v-if="columns[38].visible" show-overflow-tooltip />
      <el-table-column label="是否报价" align="center" prop="isOffer" v-if="columns[39].visible" show-overflow-tooltip />
      <el-table-column label="是否金融" align="center" prop="isFinance" v-if="columns[40].visible" show-overflow-tooltip />
      <el-table-column label="未订车原因" align="center" prop="unBookingCarReason" v-if="columns[41].visible" show-overflow-tooltip />
      <el-table-column label="跟进次数" class-name="specialColor" align="center" prop="followUpTimes"  show-overflow-tooltip />
      <el-table-column label="最新跟进日" class-name="specialColor" align="center" prop="followUpLastDate" show-overflow-tooltip />
      <el-table-column label="最新跟进级别" class-name="specialColor" align="center" prop="followUpLastLevel"   show-overflow-tooltip />
      <el-table-column label="建议下次跟进日" class-name="specialColor" align="center" prop="proposalNextFollowDate"   show-overflow-tooltip />
      <el-table-column label="跟进超期" class-name="specialColor" align="center" prop="followUpOverdueDate"   show-overflow-tooltip />
      <el-table-column label="预计到店时间" align="center" prop="preToStoreDate" v-if="columns[42].visible" show-overflow-tooltip  >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.preToStoreDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最后一次到店日期" align="center" prop="lastToStoreDate"  v-if="columns[43].visible" show-overflow-tooltip  >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lastToStoreDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="4S店" align="center" prop="storeName" v-if="columns[44].visible" show-overflow-tooltip />
      <el-table-column label="下单日期" align="center" prop="orderDate" v-if="columns[45].visible" show-overflow-tooltip  >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.orderDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="到店状态" align="center" prop="storeStatus" v-if="columns[46].visible" show-overflow-tooltip >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.to_store_status" :value="scope.row.storeStatus"/>
        </template>
      </el-table-column>
      <el-table-column  fixed label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:customer:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:customer:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改跟进模块-客户信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="75%" append-to-body>
      <el-form ref="form" :model="form" :inline="true" :rules="rules" label-width="110px"  :label-position="labelPosition">
        <el-form-item label="客户名" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入客户名" />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择性别">
            <el-option
              v-for="dict in dict.type.sys_user_sex"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="客户类型" prop="customerType">
          <el-select v-model="form.customerType" placeholder="请选择客户类型">
            <el-option
              v-for="dict in dict.type.custom_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="线索级别" prop="userType">
          <el-select v-model="form.userType" placeholder="请选择线索级别">
            <el-option
              v-for="dict in dict.type.customer_level"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入电话" />
        </el-form-item>

<!--        <el-form-item label="头像地址" prop="avatar">-->
<!--          <el-input v-model="form.avatar" placeholder="请输入头像地址" />-->
<!--        </el-form-item>-->
        <el-form-item label="线索渠道" prop="clueChannel" >
          <el-select v-model="form.clueChannel" placeholder="请选择线索渠道">
            <el-option
              v-for="dict in dict.type.clue_channels"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="线索来源" prop="dataSource">
          <el-select v-model="form.dataSource" placeholder="请选择线索来源" >
            <el-option
              v-for="dict in dict.type.customer_source"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="form.email" placeholder="请输入用户邮箱" />
        </el-form-item>
        <el-form-item label="居住区域" prop="liveAddress">
          <el-input v-model="form.liveAddress" placeholder="请输入客户居住 区县/区域" />
        </el-form-item>
        <el-form-item label="转介绍" prop="refCustomerId">
          <el-input v-model="form.refCustomerId" placeholder="请输入转介绍关联的客户ID" />
        </el-form-item>
        <el-form-item label="客户状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择客户状态">
            <el-option
              v-for="dict in dict.type.customer_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
<!--        <el-form-item label="最后登录IP" prop="loginIp">-->
<!--          <el-input v-model="form.loginIp" placeholder="请输入最后登录IP" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="最后登录时间" prop="loginDate">-->
<!--          <el-date-picker clearable-->
<!--                          v-model="form.loginDate"-->
<!--                          type="date"-->
<!--                          value-format="yyyy-MM-dd"-->
<!--                          placeholder="请选择最后登录时间">-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="是否大客户" prop="isBigCustomer">
          <el-select v-model="form.isBigCustomer" placeholder="请选择是否大客户">
            <el-option
              v-for="dict in dict.type.sys_yes_no"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="大客户" prop="bigCustomer">
          <el-select v-model="form.bigCustomer" placeholder="请选择大客户">
            <el-option
              v-for="dict in dict.type.big_customer_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="大客户单位" prop="bigCustomerDtl">
          <el-input v-model="form.bigCustomerDtl" placeholder="请输入大客户企业单位" />
        </el-form-item>
        <el-form-item label="微信" prop="wechat">
          <el-input v-model="form.wechat" placeholder="请输入微信" />
        </el-form-item>
        <el-form-item label="微信昵称" prop="nickName">
          <el-input v-model="form.nickName" placeholder="请输入客户昵称" />
        </el-form-item>
        <el-form-item label="征信情况" prop="creditInvestigation">
          <el-select v-model="form.creditInvestigation" placeholder="请选择征信情况">
            <el-option
              v-for="dict in dict.type.credit_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="付款方式" prop="payWay">
          <el-select v-model="form.payWay" placeholder="请选择付款方式">
            <el-option
              v-for="dict in dict.type.car_pay_method"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="按揭类型" prop="payMortgageType">
          <el-select v-model="form.payMortgageType" placeholder="请选择付款按揭类型">
            <el-option
              v-for="dict in dict.type.mortgage_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否有旧车" prop="isExistModel">
          <el-select v-model="form.isExistModel" placeholder="请选择是否有旧车">
            <el-option
              v-for="dict in dict.type.sys_yes_no"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="旧车型" prop="existModels">
          <el-input v-model="form.existModels" placeholder="请输入旧车置换/保有车型" />
        </el-form-item>
        <el-form-item label="旧车是否评估" prop="isAssessment">
          <el-input v-model="form.isAssessment" placeholder="请输入旧车是否评估" />
        </el-form-item>
        <el-form-item label="旧车评估价格" prop="assessmentPrice">
          <el-input v-model="form.assessmentPrice" placeholder="请输入旧车评估价格" />
        </el-form-item>
        <el-form-item label="意向车型颜色" prop="intentionCarColor">
          <el-input v-model="form.intentionCarColor" placeholder="请输入意向车型颜色" />
        </el-form-item>
        <el-form-item label="意向车型" prop="intentionCarModels">
          <el-input v-model="form.intentionCarModels" placeholder="请输入意向车系,车型" />
        </el-form-item>
        <el-form-item label="对比车型" prop="contrastCarModels">
          <el-input v-model="form.contrastCarModels" placeholder="请输入对比车型" />
        </el-form-item>
        <el-form-item label="销售员" prop="saleUser">
          <el-input v-model="form.saleUser" placeholder="请输入销售员" />
        </el-form-item>
        <el-form-item label="是否试驾" prop="isTestDrive">
          <el-input v-model="form.isTestDrive" placeholder="请输入是否试驾" />
        </el-form-item>
        <el-form-item label="是否报价" prop="isOffer">
          <el-input v-model="form.isOffer" placeholder="请输入是否报价" />
        </el-form-item>
        <el-form-item label="是否金融" prop="isFinance">
          <el-input v-model="form.isFinance" placeholder="请输入是否金融" />
        </el-form-item>
<!--        <el-form-item label="未订车原因" prop="unBookingCarReason">-->
<!--          <el-input v-model="form.unBookingCarReason" type="textarea" placeholder="请输入内容" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="预计到店时间" prop="preToStoreDate">
          <el-date-picker clearable
                          v-model="form.preToStoreDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择预计到店时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="最后一次到店日期" prop="lastToStoreDate">
          <el-date-picker clearable
                          v-model="form.lastToStoreDate"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择最后一次到店日期">
          </el-date-picker>
        </el-form-item>-->
        <el-form-item label="4S店" prop="storeName">
          <el-input v-model="form.storeName" placeholder="请输入4S店" />
        </el-form-item>
<!--        <el-form-item label="下单日期" prop="orderDate">-->
<!--          <el-date-picker clearable-->
<!--                          v-model="form.orderDate"-->
<!--                          type="date"-->
<!--                          value-format="yyyy-MM-dd"-->
<!--                          placeholder="请选择下单日期">-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->
<!--        <el-form-item label="到店状态" prop="storeStatus">-->
<!--          <el-select v-model="form.storeStatus" placeholder="请选择到店状态">-->
<!--            <el-option-->
<!--              v-for="dict in dict.type.to_store_status"-->
<!--              :key="dict.value"-->
<!--              :label="dict.label"-->
<!--              :value="dict.value"-->
<!--            ></el-option>-->
<!--          </el-select>-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCustomer, getCustomer, delCustomer, addCustomer, updateCustomer } from "@/api/system/customer";
import SearchFilter from '@/components/SearchFilter/index.vue'
export default {
  components: {SearchFilter},
  name: "Customer",
  dicts: ['credit_status', 'to_store_status', 'customer_source', 'custom_type', 'sys_yes_no', 'mortgage_type', 'big_customer_type', 'sys_user_sex', 'customer_level', 'customer_status', 'clue_channels', 'car_pay_method'],
  data() {
    return {
      searchData: {},
      labelPosition: 'right',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 跟进模块-客户信息表格数据
      customerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 到店状态时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userName: null,
        nickName: null,
        customerType: null,
        userType: null,
        email: null,
        phone: null,
        sex: null,
        avatar: null,
        clueChannel: null,
        dataSource: null,
        refCustomerId: null,
        liveAddress: null,
        status: null,
        loginIp: null,
        loginDate: null,
        createTime: null,
        remark: null,
        isBigCustomer: null,
        bigCustomer: null,
        bigCustomerDtl: null,
        wechat: null,
        buyCarType: null,
        creditInvestigation: null,
        payWay: null,
        payMortgageType: null,
        isExistModel: null,
        existModels: null,
        isAssessment: null,
        assessmentPrice: null,
        intentionCarColor: null,
        intentionCarModels: null,
        contrastCarModels: null,
        saleUser: null,
        isTestDrive: null,
        isOffer: null,
        isFinance: null,
        unBookingCarReason: null,
        preToStoreDate: null,
        lastToStoreDate: null,
        storeName: null,
        orderDate: null,
        storeStatus: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userName: [
          { required: true, message: "客户名不能为空", trigger: "blur" }
        ],
        customerType: [
          { required: true, message: "客户类型不能为空", trigger: "change" }
        ],
        userType: [
          { required: true, message: "线索级别不能为空", trigger: "change" }
        ],
        sex: [
          { required: true, message: "性别不能为空", trigger: "change" }
        ],
      },
      // 列表的列的显示隐藏设置
      columns:[
        { key: 0, label: `客户ID`, visible: true },
        { key: 1, label: `客户名`, visible: true },
        { key: 2, label: `客户昵称`, visible: true },
        { key: 3, label: `客户类型`, visible: true },
        { key: 4, label: `线索级别`, visible: true },
        { key: 5, label: `用户邮箱`, visible: true },
        { key: 6, label: `电话`, visible: true },
        { key: 7, label: `性别`, visible: true },
        { key: 8, label: `头像地址`, visible: true },
        { key: 9, label: `线索渠道`, visible: true },
        { key: 10, label: `线索来源`, visible: true },
        { key: 11, label: `转介绍关联的客户ID`, visible: true },
        { key: 12, label: `客户居住 区县/区域`, visible: true },
        { key: 13, label: `客户状态`, visible: true },
        { key: 14, label: `删除标志（0代表存在 2代表删除）`, visible: true },
        { key: 15, label: `最后登录IP`, visible: true },
        { key: 16, label: `最后登录时间`, visible: true },
        { key: 17, label: `创建者`, visible: true },
        { key: 18, label: `创建时间`, visible: true },
        { key: 19, label: `更新者`, visible: true },
        { key: 20, label: `更新时间`, visible: true },
        { key: 21, label: `备注`, visible: true },
        { key: 22, label: `是否大客户`, visible: true },
        { key: 23, label: `大客户`, visible: true },
        { key: 24, label: `大客户企业单位`, visible: true },
        { key: 25, label: `微信`, visible: true },
        { key: 26, label: `购车类型`, visible: true },
        { key: 27, label: `征信情况`, visible: true },
        { key: 28, label: `付款方式`, visible: true },
        { key: 29, label: `付款按揭类型`, visible: true },
        { key: 30, label: `是否有旧车`, visible: true },
        { key: 31, label: `旧车置换/保有车型`, visible: true },
        { key: 32, label: `旧车是否评估`, visible: true },
        { key: 33, label: `旧车评估价格`, visible: true },
        { key: 34, label: `意向车型颜色`, visible: true },
        { key: 35, label: `意向车系,车型`, visible: true },
        { key: 36, label: `对比车型`, visible: true },
        { key: 37, label: `销售员`, visible: true },
        { key: 38, label: `是否试驾`, visible: true },
        { key: 39, label: `是否报价`, visible: true },
        { key: 40, label: `是否金融`, visible: true },
        { key: 41, label: `未订车原因`, visible: true },
        { key: 42, label: `预计到店时间`, visible: true },
        { key: 43, label: `最后一次到店日期`, visible: true },
        { key: 44, label: `4S店`, visible: true },
        { key: 45, label: `下单日期`, visible: true },
        { key: 46, label: `到店状态`, visible: true },
      ],
    };
  },
  created() {
    this.getList();
    //列表分页列的动态显示配置
    var columns = JSON.parse(localStorage.getItem(this.$options.name));
    if(columns){
      this.columns = columns;
    }
  },
  methods: {
    /** 查询跟进模块-客户信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      listCustomer(this.queryParams).then(response => {
        this.customerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    search() {},
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userName: null,
        nickName: null,
        customerType: null,
        userType: null,
        email: null,
        phone: null,
        sex: null,
        avatar: null,
        clueChannel: null,
        dataSource: null,
        refCustomerId: null,
        liveAddress: null,
        status: null,
        delFlag: null,
        loginIp: null,
        loginDate: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        isBigCustomer: null,
        bigCustomer: null,
        bigCustomerDtl: null,
        wechat: null,
        buyCarType: null,
        creditInvestigation: null,
        payWay: null,
        payMortgageType: null,
        isExistModel: null,
        existModelId:null,
        existModels: null,
        isAssessment: null,
        assessmentPrice: null,
        intentionCarColor: null,
        intentionCarModels: null,
        intentionCarModelId:null,
        contrastCarModels: null,
        saleUser: null,
        isTestDrive: null,
        isOffer: null,
        isFinance: null,
        unBookingCarReason: null,
        preToStoreDate: null,
        lastToStoreDate: null,
        storeName: null,
        orderDate: null,
        storeStatus: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateTime = [];
      this.queryParams={};
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.form.status = 'potential';
      this.open = true;
      this.title = "添加跟进模块-客户信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCustomer(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改跟进模块-客户信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCustomer(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCustomer(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除跟进模块-客户信息编号为"' + ids + '"的数据项？').then(function() {
        return delCustomer(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/customer/export', {
        ...this.queryParams
      }, `customer_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
